package com.goomba.filter;

import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.MessageSelector;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

public class UserPropertyConsumer {

    public static void main(String[] args) throws Exception {

        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("tag_filter_group2");

        consumer.setNamesrvAddr(Commons.nameSrvAddr);


        // 配置文件中需要加入 enablePropertyFilter=true 开启数据，否则数据是不能使用的
        consumer.subscribe("FilterTopic",  MessageSelector.bySql("index > 12 "));
        consumer.registerMessageListener((MessageListenerConcurrently) (list, ConsumeConcurrentlyContext) -> {

            for (MessageExt ext : list) {
                System.out.println("获取到的数据是" + new String(ext.getBody()));
            }

            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        });




        consumer.start();
    }
}
